package com.zhouyong.util;

import com.zhouyong.protocol.ObjectSerialEnum;

import java.io.InputStream;
import java.util.Objects;
import java.util.Properties;

public class Utils {

    private static Properties properties;

    static {
        try {
            InputStream resource = Utils.class.getResourceAsStream("/application.properties");
            properties = new Properties();
            properties.load(resource);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 返回对应的序列化方式
     *
     * @return
     * @throws Exception
     */
    public static ObjectSerialEnum getSerializerType() throws Exception {
        String algorithm = properties.getProperty("serializer.algorithm");
        if (Objects.isNull(algorithm)) {
            return ObjectSerialEnum.JDK;
        } else {
            return ObjectSerialEnum.valueOf(algorithm);
        }
    }

}
